﻿using System.Data.Entity;
using System.Data.Objects;

namespace UnitOfWork
{
    public class DatabaseFactory<TContext> : Disposable, IDatabaseFactory<TContext> where TContext : DbContext, new()
    {
        private TContext _dataContext;
        public TContext Get()
        {
            return _dataContext ?? (_dataContext = new TContext());
        }
        protected override void DisposeCore()
        {
            if (_dataContext != null)
                _dataContext.Dispose();
        }
    }
}
